<template>
  <div class="box">
    <!-- 输入框 -->
    <div class="search">
      <el-form
        :inline="true"
        :model="ru"
        class="demo-form-inline"
        :rules="rules"
        ref="ru"
        status-icon
        @submit.native.prevent
      >
        <el-form-item label="请输入商品类型" prop="name">
          <el-input
            v-model="ru.name"
            placeholder="请输入商品类型"
            @change="hh(ru.name, $event)"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ru')">查询</el-button>
          <el-button type="primary" @click="resetForm('ru')">重置</el-button>
          <el-button type="primary" @click="toAddGood">跳转新增页面</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!-- 表格区域 -->
    <div class="table">
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="date" label="日期" width="180">
        </el-table-column>
        <el-table-column prop="name" label="姓名" width="180">
        </el-table-column>
        <el-table-column prop="address" label="地址"> </el-table-column>
        <el-table-column label="操作" width="200">
          <template slot-scope="scope">
            <el-button @click="open" size="small"> 新增 </el-button>
            <el-button
              @click.native.prevent="deleteRow(scope.$index, tableData)"
              size="small"
            >
              移除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页 -->
    <el-pagination
      style="text-align: center; margin-top: 40px"
      background
      layout="total,prev, pager, next,jumper"
      :total="1000"
    >
    </el-pagination>
    <!-- 弹框 -->
    <v-Dialog ref="open"></v-Dialog>
  </div>
</template>

<script>
import Dialog from "./components/aDialog.vue"
export default {
  components: {
    'v-Dialog':Dialog
    },
  data() {
    let va = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入名字"));
      } else {
        callback();
      }
    };
    return {
      ru: {
        name: "",
      },
      rules: {
        name: [
           
          { validator: va, trigger: "blur" },
          { required: true},
        ],
      },
      tableData: [
        {
          date: "2016-05-02",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1517 弄",
        },
        {
          date: "2016-05-01",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1519 弄",
        },
        {
          date: "2016-05-03",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1516 弄",
        },
      ],
    };
  },
  methods: {
    open(){
      console.log(this.$refs.open)
      this.$refs.open.dialogVisible=true
    },
    toAddGood(){
      this.$router.push({
        path:"/addgood/true"
      })
    },
    hh(v,e){
      console.log(v,e)
    //  if(e.keyCode==13){return false;}
    },
    deleteRow(index, rows) {
      rows.splice(index, 1);
    },
    resetForm(name) {
      this.$refs[name].resetFields();
    },
    submitForm(name) {
  
      this.$refs[name].validate((valid) => {
        if (valid) {
         
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>

<style lang="less" scope>
.box {
  margin: 20px;
  .search {
    padding-top: 10px;
    input {
      width: 600px;
      // margin-right: 30px;
    }
    button {
      margin-left: 20px;
    }
  }
  .table {
    margin-top: 10px;
  }
}
</style>